<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>食堂订货统计</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
</head>
<style>
	.numShow{
		width:90%;
		text-align: right;
		font-size: 18px;
		padding:0 5% 20px;
	}
	.numShow span:last-child{
		margin-left:20px;
	}
</style>
<body>
    <div class="maincontainer">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <form id="queryForm" class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">食堂名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="canteenName" autocomplete="off" class="layui-input" placeholder="食堂名称">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">统计时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="selectTime" placeholder=" - ">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn"  lay-submit lay-filter="searchBth">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary reReset" >重置</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
            </div>
			<div class="numShow"></div>
        </div>

    </div>
</body>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container toolbarDemo">
		<button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="export">导出</button>
	</div>
</script>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
    
    layui.config({
        base: 'plugins/layui/modules/',
    }).use(['http', 'table', 'form', 'laydate'], function() {
        var http = layui.http,
            table = layui.table,
            form = layui.form,
            laydate = layui.laydate;
			
			$('.reReset').click();
			
        http.checking(function() {
            //时间
            laydate.render({
                elem: '#selectTime'
                ,theme: '#fbaf7e'
                ,range: "-"
            });
            
            var param = {};

            // 角色列表
            var selectTable;
            selectTable = http.table({
                elem: '#selectTable',
                url: 'food/manager/count/countCanteenOrderGoodCount',
                method: 'get',
                id: 'selectTable',
                toolbar: '#toolbarDemo',
                done: function(res, curr, count){
                    console.log(res);
                    var html = '<span>进货数量：<text>'+res.all.goodCount+'</text></span><span>合计：<text style="color:#f56643">'+res.all.totalMoney+'</text></span>';
                    $(".numShow").html(html);
                },
                cols: [[
                    {title:'序号',type:'numbers',fixed: 'left'}
                    ,{field:'canteenName', title: '食堂名称', align : 'center'}
                    ,{field:'goodCount', title: '进货数量', align : 'center'}
                    ,{field:'totalPrice', title: '金额', align : 'center'}
					,{field:'orderCount', title: '订单数量', align : 'center'}
                    ,{field:'', title: '操作', align : 'center',fixed: 'right',width: 230,
                        templet: function (d) {
                            var html = '';
                            html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="seeOrder" >查看订单</button>'
                            return html;
                        }
                    }
                ]]
            });

            //查询
            form.on('submit(searchBth)', function (data) {
                let _data = data.field;
                    param = _data;
                var startTime = $('#selectTime').val()?$('#selectTime').val().split(' - ')[0]:'';
                var endTime = $('#selectTime').val()?$('#selectTime').val().split(' - ')[1]:'';
                param.startTime = startTime;
                param.endTime = endTime;
                selectTable.reload({
                    page:{curr:1},
                    where: param
                })
            })

            table.on('tool(selectTable)', function(obj){
                var data = obj.data;
                if(obj.event=='seeOrder'){
                    // 查看订单
                    var inParam = {
                        canteenId:data.canteenId,
                    }
                    if(param.startTime){
                        inParam.startTime = param.startTime
                    }
                    if(param.endTime){
                        inParam.endTime = param.endTime
                    }
                    let paramsArray = [];
                    Object.keys(inParam).forEach(key => paramsArray.push(key + '=' + inParam[key]))  
                    location.href = "order.html?"+paramsArray.join('&')
                }
            })

            table.on('toolbar(selectTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                var data = checkStatus.data; //获取选中行数据
                if(obj.event=='export'){ // 导出
                    param.page =  1;
                    param.limit =  10;
                    param.authentication = localStorage.getItem('xi-head-authentication');
                    let paramsArray = [];
                    Object.keys(param).forEach(key => paramsArray.push(key + '=' + param[key]))  
                    window.open(TUrl+"food/manager/count/exportCanteenOrderGoodCount?"+paramsArray.join('&'))
                }
            })
        })

    })

</script>
</html>